//
//  ZRTabBarController.swift
//  Sina
//
//  Created by 张锐 on 16/2/24.
//  Copyright © 2016年 zhangr. All rights reserved.
//

import UIKit

class ZRTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
       
        
        //加载子控制器
        addChildViewController()
        
        //加载自定义tabbar
        
        let zrTabBar = ZRTabBar()
        
        //中间按钮点击事件
        zrTabBar.centerButton.addTarget(self, action: "centerButtonClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        
        
        //通过KVC设置只读属性
        setValue(zrTabBar, forKey: "tabBar")
        
        
 
    }
    /**
     tabBar 中间按钮点击事件
     */
    func centerButtonClick(){
    
        let pulishVC = ZRPulishViewController()
        
        presentViewController(UINavigationController(rootViewController: pulishVC), animated: true) { () -> Void in
            
        }
    
    }
    /**
     重载加子控制器方法，加入所以子控制器
     */
    func addChildViewController() {
        
        addChildViewController(ZRHomeViewController(), title: "首页", image: "tabbar_home")
        
        addChildViewController(ZRMessageViewController(), title: "消息", image: "tabbar_message_center")
        
        addChildViewController(ZRFindViewController(), title: "发现", image: "tabbar_discover")
        
        addChildViewController(ZRSettingViewController(), title: "设置", image: "tabbar_profile")
        
    }
    
    
    /**
     重载加子控制器方法，加入一个控制器的具体
     
     - parameter childController: 子控制器
     - parameter title:           子控制器标题
     - parameter image:           子控制器tabbar图片名称
     */
     func addChildViewController(childController: UIViewController,title : String,image : String ) {
        
        childController.title = title
        
        childController.tabBarItem.image = UIImage(named: image)
        
        let highlightedImage = "\(image)_highlighted"
        
        childController.tabBarItem.selectedImage = UIImage(named: highlightedImage)
        
        addChildViewController(UINavigationController(rootViewController: childController))
        
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
